package be.ipl.Diavolo.domaine;

import java.io.Serializable;
import java.util.Random;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

@SuppressWarnings("serial")
@Entity
@Table(name="DEORDRE", schema="DIAPERO")
public class DeOrdre implements Serializable{
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	
	@Min(1) @Max(6)
	private int ordre;
	
	@Transient
	private Random r;

	public DeOrdre() {
		r = new Random();
	}

	public int getOrdre() {
		return ordre;
	}

	public void setOrdre(int ordre) {
		this.ordre = ordre;
	}
	
	public int lancerDe(){
		this.setOrdre(1 + r.nextInt(6));
		return ordre;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		DeOrdre other = (DeOrdre) obj;
		if (id != other.id)
			return false;
		return true;
	}
}
